package com.sixth.controller;

import com.sixth.bean.MarketBrand;
import com.sixth.bean.common.BasePageInfo;
import com.sixth.bean.common.BaseRespVo;
import com.sixth.bean.common.BaseResultVo;
import com.sixth.bean.vo.AdminBrandCreateVo;
import com.sixth.constant.Constant;
import com.sixth.service.AdminBrandService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @ClassName AdminBrandController
 * @Description TODO
 * @Author XiaoWJ
 * @Date 2022/9/8 9:03
 **/

@RestController
@RequestMapping("admin/brand")
public class AdminBrandController {

    @Autowired
    AdminBrandService adminBrandService;

    /**
     * 根据条件查询品牌信息
     *
     * @Param basePageInfo, userId, valueId
     * @Return BaseRespVo<Object>
     * @author XiaoWJ
     * @date 2022/9/7 20:10
     */

    @RequiresPermissions(value = {"admin:brand:list"}, logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo basePageInfo, Integer id, String name) {

        Object result = adminBrandService.list(basePageInfo, id, name);

        return BaseRespVo.ok(result);

    }


    /**
     * 添加品牌制造商
     *
     * @Param
     * @Return
     * @author XiaoWJ
     * @date 2022/9/8 15:16
     */
    @RequiresPermissions(value = {"admin:brand:create"}, logical = Logical.OR)
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MarketBrand marketBrand) {
        AdminBrandCreateVo adminBrandCreateVo = adminBrandService.crate(marketBrand);

        return BaseRespVo.ok(adminBrandCreateVo);

    }


    /**
     * 更新品牌制造商
     *
     * @Param
     * @Return
     * @author XiaoWJ
     * @date 2022/9/8 15:16
     */
    @RequiresPermissions(value = {"admin:brand:update"}, logical = Logical.OR)
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody AdminBrandCreateVo adminBrandCreateVo) {
        adminBrandCreateVo.setUpdateTime(new Date());

        int code = adminBrandService.update(adminBrandCreateVo);

        if (code == Constant.OK) {
            return BaseRespVo.ok(adminBrandCreateVo);
        }
        return BaseRespVo.invalidData();
    }

    /**
     * 逻辑删除品牌制造商
     *
     * @Param
     * @Return
     * @author XiaoWJ
     * @date 2022/9/8 15:16
     */




    @RequiresPermissions(value = {"admin:brand:delete"}, logical = Logical.OR)

    @RequestMapping("delete")
    public BaseResultVo delete(@RequestBody AdminBrandCreateVo adminBrandCreateVo) {

        adminBrandService.delete(adminBrandCreateVo.getId());
        return BaseResultVo.ok();

    }


}
